package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.ProductInfo;
import cn.shop.dys.constant.CommonConstant;

/**
 * Created by liulu on 2016/4/23.
 */
public class CollectAdapter extends BaseAdapter {
    private Context mContext;
    private List<ProductInfo> products;

    public CollectAdapter(Context mContext, List<ProductInfo> products) {
        this.mContext = mContext;
        this.products = products;
    }

    @Override
    public int getCount() {
        return products == null ? 0 : products.size();
    }

    @Override
    public ProductInfo getItem(int position) {
        return products.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            view = convertView.inflate(mContext, R.layout.collect_item, null);
            viewHolder.pic = (ImageView) view.findViewById(R.id.scj_pic);
            viewHolder.title = (TextView) view.findViewById(R.id.scj_title);
            viewHolder.markerPrice = (TextView) view.findViewById(R.id.scj_marketPrice);
            viewHolder.vipPrice = (TextView) view.findViewById(R.id.scj_vipPrice);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        ProductInfo product = products.get(position);
        viewHolder.title.setText(product.getName());
        viewHolder.vipPrice.setText(product.getPrice()+"");
        viewHolder.markerPrice.setText(product.getMarketPrice()+"");
        String url = CommonConstant.HOST+product.getPic();
        Glide.with(mContext)
                .load(url)
                .fitCenter()
                .crossFade()
                .into(viewHolder.pic);

        return view;
    }

    class ViewHolder {
        private ImageView pic;
        private TextView title;
        private TextView markerPrice;
        private TextView vipPrice;

    }

}
